package com.mc.lp.security.user;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import com.mc.lp.database.entity.helper.UserEntityHelper;
import com.mc.lp.service.UserService;
import com.mc.lp.shared.vo.UserVO;

/**
 * @author: deepak.verma
 * @description: main class to authenticate the user.
 * */
@Service("userAuthenticationService")
public class UserAuthenticationService implements UserDetailsService {

	@Resource
	private UserService userService;

	@Resource
	private UserEntityHelper userEntityHelper;

	/*
	 * @Resource private AccessControlService acceControlService;
	 */

	private Logger log = Logger.getLogger(UserAuthenticationService.class);

	public UserDetails loadUserByUsername(String login) throws UsernameNotFoundException {
		
		log.debug("Trying logging with user:" + login);
		UserVO user = userService.getUserByUserName(login);
		log.debug("Trying logging with user, user found:" + user);
		return user;

	}

	public UserService getUserService() {
		return userService;
	}

	public void setUserService(UserService userService) {
		this.userService = userService;
	}
}